package com.boang.lock;

/*
  @author: 13813
  @date: 2024/11/26 13:57
*/
public class TicketDemo02 implements Runnable {
    private int num = 20;

    @Override
    public void run() {
        while (true) {
            //获取当前线程
            if (num > 0) {
                try {
                    Thread.sleep(300);//t0 t1 t2
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + ":" + num--); //t0 0 t1 -1 t2 -2
            }
        }
    }
}
